#include "readerwriter.h"

namespace concurrent {

ReaderWriter::ReaderWriter() {
	if ( 0 != pthread_rwlock_init(&_lock, NULL) ) {
	}
}

ReaderWriter::~ReaderWriter() {
	destroy();
}

bool ReaderWriter::destroy() {
	return (0 == pthread_rwlock_destroy(&_lock));
}
	
bool ReaderWriter::readLock() {
	return (0 == pthread_rwlock_rdlock(&_lock));
}

bool ReaderWriter::tryReadLock() {
	return (0 == pthread_rwlock_tryrdlock(&_lock));
}

bool ReaderWriter::writeLock() {
	return (0 == pthread_rwlock_wrlock(&_lock));
}

bool ReaderWriter::tryWriteLock() {
	return (0 == pthread_rwlock_trywrlock(&_lock));
}

bool ReaderWriter::unlock() {
	return (0 == pthread_rwlock_unlock(&_lock));
}

}

